<?php
// filename : head.php

if( isset( $_POST[ 'Upload' ] ) ) {
    $uniqid = md5(uniqid(microtime(true),true));
    $target = "uploads/" ;
    $target = $target . $uniqid  . basename( $_FILES['uploaded']['name']);
    
    //记录文件信息
    $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
    echo "upload name " . $uploaded_name . "<br>";
    echo "filename len = ". strlen($uploaded_name);
    $uploaded_ext  = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1);
    echo "ext: ". $uploaded_ext . "<br>";
    $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ];
    $uploaded_tmp  = $_FILES[ 'uploaded' ][ 'tmp_name' ];
    
    //识别文件头信息
    if( exif_imagetype($_FILES['uploadedfile']['tmp_name']) ) {
        if( !move_uploaded_file( $uploaded_tmp, $target ) ) {
            echo '<pre>';
            echo 'upload fail.';
            echo '</pre>';
        }
        else {
            echo "upload succ <br> ";
            echo "<img src='$target'>";
        }
    }
    else {
        echo "<pre>only png and jpeg allowed ,or too big</pre>";
    }
}else{
    include "form.html";
    show_source(__FILE__);
}
?>